function datesn = YMD2serial(YMD)
% YMD2serial - YMD to serial date conversion
%
%       DATESN = YMD2serial(YMD)
%
% Let YMD be a N-by-7 char array of dates in YYMMMDD format. This function 
% provides the N-by-1 vector of corresponding dates in MATLAB serial date 
% number form.
% For example, YMD = 05JAN02, which corresponds to 2-Jan-2005, is converted
% into DATESN = 732314.
% Please note that YY >= 80 is interpreted as a 20th century year and 
% YY < 80 is interpreded as a 21th century year instead.

% G. Teza, 2022

if ~ischar(YMD) || (size(YMD,2) ~= 7)
    error('Invalid input char array');
end

yy = YMD(:,1:2);
yyn = str2num(yy); %#ok<ST2NM> 
I1 = yyn >= 80;
I2 = yyn <  80;
yyn(I1) = 1900+yyn(I1);
yyn(I2) = 2000+yyn(I2);
yyyy = num2str(yyn);
mm = YMD(:,3:5);
dd = YMD(:,6:7);

eldash = repelem('-',size(YMD,1))';   % to allow horzcat with dash
datess  = [dd eldash mm eldash yyyy];

datesn = datenum(datess);